﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Common;

public partial class website_admin__root_LeftFrame : PageBase
{
    protected string ArrRolesIdFinter = "";
    public string CurrentMenuId = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;

        PageBegin(); 

        string arrRoleId = "", catalogId = "", SQL = "";
        string _roleid = this.RoleId;
        for (int i = 0; i < _roleid.Split('|').Length; i++)
        {
            arrRoleId += "'" + _roleid.Split('|')[i] + "',";
        }
        if (arrRoleId != "")
        {
            arrRoleId += "|";
            arrRoleId = arrRoleId.Replace(",|", "");

            SQL += " AND CatalogId IN (SELECT DISTINCT CatalogId FROM PersonalizationCatalog WHERE OwnerId IN (" + arrRoleId + "))";
        }
        else { SQL += " AND 1 <> 1"; }

        ArrRolesIdFinter = SQL;

        CurrentMenuId = BLL.CommonBLL.ExecuteScalar("System_CatalogBase", "TOP 1 CatalogId", SQL + " AND Layer = 1 AND DeletionStateCode = 0 ORDER BY [Sort] ASC").ToString();
 

        DataTable dtCatalog = BLL.CommonBLL.Select("System_CatalogBase", "*", SQL + " AND DeletionStateCode = 0 ORDER BY [Sort] ASC");
        rptPersonalCatalog.DataSource = dtCatalog.DefaultView;
        rptPersonalCatalog.DataBind();
    }

    /// <summary>
    /// 绑定嵌套控件
    /// </summary>
    protected void rptPersonalCatalog_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptPersonalCatalogItem = (Repeater)e.Item.FindControl("rptPersonalCatalogItem");
            DataRowView rowv = (DataRowView)e.Item.DataItem;

            rptPersonalCatalogItem.DataSource = BLL.CommonBLL.Select("System_CatalogBase", "*", ArrRolesIdFinter + " AND ParentId = " + Convert.ToString(rowv["CatalogId"]) + " AND DeletionStateCode = 0 ORDER BY [Sort] ASC");
            rptPersonalCatalogItem.DataBind();
        }
    }
}
